<?php
// +----------------------------------------------------------------------
// | 幕小铺
// +----------------------------------------------------------------------
// | 版权所有 2016~2020 幕小铺科技（大连）有限公司
// +----------------------------------------------------------------------
// | 2020/03/14
// +----------------------------------------------------------------------

namespace app\video\model;

use think\Model;
use util\Tree;


/**
 * 视频分类标签 模型
 * @package app\user_center\model
 */
class VideoPlayClassLabel extends Model
{
    // 设置当前模型对应的完整数据表名称
    protected $table = 'xm_video_play_class_label';

    /**
     * 添加标签
     * @param array $list 	标签
     * @author shiqiang <976162041@qq.com>
     * @return bool
     */
    public function addDataTage($title){
        //判断是否已经存在这个标签
        $map = [];
        $map['title'] = trim($title);
        $res = $this -> where($map) -> find();
        if($res){
            return array_out(200, 'success', $res->id);
        }
        $data = [];
        $data['title'] = $title;
        $res = $this -> isUpdate(false)->data($data, true) -> save();
        if($res){
            return array_out(200, 'success', $this->id);
        }else{
            return array_out(-1001, 'error');
        }
    }

    /**
     * 添加数据
     * @param array $list 	标签
     * @author shiqiang <976162041@qq.com>
     * @return bool
     */
    public function addData($list){
        $res = $this -> isUpdate(false) -> saveAll($list);
        if($res){
            return array_out(200, 'success', $res -> column('id'));
        }else{
            return array_out(-1001, 'error');
        }
    }
	
	/**
     * 编辑数据
     * @param int $id 		
     * @param string $title 	标签
     * @author shiqiang <976162041@qq.com>
     * @return bool
     */
    public function editData($id, $title){
        $data['title']   = $title;
        $res = $this -> where('id', $id) -> update($data);
        if($res){
            return array_out(200, 'success');
        }else{
            return array_out(-1001, 'error');
        }
    }

    /**
     * 删除数据
     * @param int $id
     * @author shiqiang <976162041@qq.com>
     * @return bool
     */
    public function deleteData($id){
        $map        = [];
        $map['id']     = $id;
        $res = self::destroy(function($query) use ($map){
            $query->where($map);
        });
        if($res){
            return array_out(200, 'success');
        }else{
            return array_out(-1001, 'error');
        }
    }
}
